<?php
/*
 * 
 */
require_once 'z.php';

$soapClient = new soapclient($app_config->$argv[1]->param->currency->xrate_url);

$currencies = new Zend_Db_Table(array('name' => 'currencies', 'primary' => 'CurrencyId'));
$xrates = new Zend_Db_Table(array('name' => 'exchange_rates', 'primary' => 'ExchangeRateId'));

$reference = $currencies->find($app_config->$argv[1]->param->currency->reference)->current();
$data = $currencies->fetchAll($currencies->select()
        ->where('CurrencyId != ?', $reference->CurrencyId));

foreach($data as $currency) { 
    $result = $soapClient->Convert(array(
        'CurrencyFrom' => $reference->Code,
        'CurrencyTo' => $currency->Code,
        'ValueFrom' => (double)1,
        'UserKey' => $app_config->$argv[1]->param->currency->xrate_key,
    ));
    $xrates->insert(array(
        'CurrencyId' => $currency->CurrencyId, 
        'Rate' => $result->ConvertResult, 
        'Date' => date('Y-m-d')));
}    
$xrates->insert(array(
        'CurrencyId' => $reference->CurrencyId, 
        'Rate' => 1, 
        'Date' => date('Y-m-d')));
?>